<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
            .ui-commandButton-wizard-selected{
                background-color: #D20005;
                font-weight: bold;
                color: #000000;
            }
            .ui-commandButton-wizard-unselected{
                background-color: #D20005;
                font-weight: bold;
                color: #AFAFAF;
            }
        </style>
        <h2>Create Sales Invoice</h2>
        <h:form id="salesInvoice" style="font-size: 85%">
            <br/>
            <p:panel id="invoice1">
                
                <h2>Invoice</h2>

                <br/>
                <br/>
                <h:panelGrid columns="2" style="width: 100%" >
                    
                    <h:panelGrid columns="1" style="border-style: solid; border-width: thin; width: 100%" >
                        <h:panelGrid columns="2" cellpadding="10" style="width: 100%">
                            <h:outputLabel style="font-weight: bold" value="Client ID: "/>
                            <h:outputText id="clientId" value="#{sbpInvoiceManagerBean.invoice.customer.clientId}"/>
                            <h:outputLabel style="font-weight: bold" value="Company Name: "/>
                            <h:outputText id="companyName" value="#{sbpInvoiceManagerBean.invoice.customer.companyName}" />
                            <h:outputText value=""/>
                            <h:outputText value=""/>
                        </h:panelGrid>
                        <h:panelGrid columns="1" style="width: 100%; padding: 0px 10px">
                            <h:outputText value="Billing Address" style="font-weight: bold; font-size: 110%"/>
                            <p:separator/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.customer.billingAddress.addressLine1}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.addressLine2}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.city}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.stateName}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.country}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.zipCode}" />
                            <h:outputText value=""/>
                            <h:outputText value=""/>
                            
                            <h:outputText value="Shipping Address" style="font-weight: bold; font-size: 110%"/>
                            <p:separator/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.addressLine1}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.addressLine2}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.city}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.stateName}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.country}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.zipCode}" />
                            <h:outputText value=""/>
                            <h:outputText value=""/>
                        </h:panelGrid>
                    </h:panelGrid>

                    <h:panelGrid columns="4" cellpadding="10" style="width: 100%">
                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Date: "/>
                        <h:outputText value="#{sbpInvoiceManagerBean.invoice.invoiceDate}" style="text-align: left">
                            <f:convertDateTime pattern="MMMM dd, yyyyy"/>
                        </h:outputText>
                        
                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Invoice Number: "/>
                        <h:outputText value="#{sbpInvoiceManagerBean.invoice.invoiceId}" />
                        
                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Purchase Order Number: "/>
                        <h:outputText value="#{sbpInvoiceManagerBean.invoice.poNumber}" />
                        
                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Status: "/>
                        <h:selectOneRadio disabled="true" value="#{sbpInvoiceManagerBean.invoice.paid}">
                            <f:selectItem itemLabel="Paid" itemValue="true"/>
                            <f:selectItem itemLabel="Unpaid" itemValue="false"/>
                        </h:selectOneRadio>
                    </h:panelGrid>
                </h:panelGrid>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Delivery Order" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Delivery Order"/> 
                <br/>
                <p:dataTable id="olilTable" var="oneIL" value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.itemLines}" emptyMessage="No products selected">
                    <p:column headerText="Product Type" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.product.productType}"/>
                    </p:column>
                    <p:column rendered="#{oneIL.qtyOrderedCase != 0}">
                        <f:facet name="header">
                            Quantity <br/> Ordered Case
                        </f:facet>
                        <h:outputText value="#{oneIL.qtyOrderedCase}"/>
                    </p:column>
                    <p:column rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (soManagerBean.salesOrder.currency)}">
                        <f:facet name="header">
                            Case Unit <br/> Price (SGD)
                        </f:facet>
                        <h:outputText value="#{oneIL.unitPriceSGD}" />
                    </p:column>
                    <p:column rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (!soManagerBean.salesOrder.currency)}">
                        <f:facet name="header">
                            Case Unit <br/> Price (USD)
                        </f:facet>
                        <h:outputText value="#{oneIL.unitPriceUSD}" />
                    </p:column>
                    <p:column headerText="Member Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.memberDiscount}" />
                    </p:column>
                    <p:column headerText="Order Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.orderDiscount}" />
                    </p:column>
                    <p:column headerText="Special Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.specialDiscount}" />
                    </p:column>
                    <p:column headerText="Sub-total" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.subTotal}" />
                    </p:column>
                </p:dataTable>
                <br/>

                <br/>
                <br/>
                <p:separator style="height:1px; border-color: #000000; color: #000000; background-color: #000000; outline-color: #000000"/> 
                <div align="right">
                    <h3>
                        <h:panelGrid columns ="2" cellpadding="2" style="text-align: right">
                            <h:outputLabel style="font-weight: bold" value="Sub-total: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.subtotal}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Order Discount: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.orderDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Member Discount: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.memberDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Special Discount: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.specialDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Tax: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.tax}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h3>
                    <h2>
                        <h:panelGrid columns ="2" cellpadding="10">
                            <h:outputLabel for="total" style="font-weight: bold" value="Total: "/>
                            <h:outputText id="total" value="#{sbpInvoiceManagerBean.invoice.total}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h2>
                </div>

            </p:panel>
            
            <br/>
            <br/>
            <br/>
            <div align="right">
                <p:commandButton value="Confirm Sales Invoice" action="#{sbpInvoiceManagerBean.saveInvoice()}" image="ui-icon ui-icon-disk" />
                <p:commandButton value="Cancel" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="cancellation"/>
            </div>
            <br/>
            <br/>
        </h:form>

        <p:confirmDialog message="Are you sure about cancelling the sales invoice?" width="200"  
                         showEffect="explode" hideEffect="explode"  
                         header="Initiating cancellation" severity="alert" widgetVar="confirmation">
            <h:form id="confirmDialog">
                <p:commandButton value="Yes" update="growl" action="#{sbpInvoiceManagerBean.cancelSalesInvoice}" oncomplete="confirmation.hide()"/>  
                <p:commandButton value="No" onclick="confirmation.hide()" type="button" />
            </h:form>
        </p:confirmDialog>



    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>